package org.zhuzx.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotNull;

/**
 * 封装了基础的分页参数，已标注@NotNull注解、swagger注解。<br>
 * 为了通用性，swagger注解中并未标记required=true，在实际业务场景再决定是否必传（是否开启@Validated）。
 * @author zhuzx 2022/7/4
 */
@Getter
@Setter
@ApiModel
public class PageParam {

	@NotNull
	@ApiModelProperty(value = "分页参数-当前是第几页，从1开始。", position = 1005)
	private Integer currentPage;
	
	@NotNull
	@ApiModelProperty(value = "分页参数-一页的数据量", position = 1006)
	private Integer pageSize;

	private void checkPageParam() {
		BizAssert.mustTrue(GeneralUtil.isAllHaveOrNoneHaveValue(currentPage, pageSize),
				"currentPage和pageSize必须搭配使用，不能只传一个。");
	}

	public Integer getCurrentPage() {
		checkPageParam();
		return currentPage;
	}

	public Integer getPageSize() {
		checkPageParam();
		return pageSize;
	}
	
}